

/**
 * @description:
 * @Author Levi
 * @Date 2022/5/20 15:04
 * @Version 3.0 (created by JDK8)
 */
public class Pet implements Comparable{
    private String name;
    private Integer age;
    private Double weight;

    public Pet() {
        name = "No name yet.";
        age = 0;
        weight = 0.0;
    }

    public Pet(String name, Integer age, Double weight) {
        this.name = name;
        if ((age < 0) || (weight < 0)) {
            System.out.println("Error: Negative age or weight.");
            System.exit(0);
        } else {
            this.age = age;
            this.weight = weight;
        }
    }

    public void setPet(String name, Integer age, Double weight) {
        this.name = name;
        if ((age < 0) || (weight < 0)) {
            System.out.println("Error: Negative age or weight.");
            System.exit(0);
        } else {
            this.age = age;
            this.weight = weight;
        }
    }

    public Pet(String name) {
        this.name = name;
        age = 0;
        weight = 0.0;
    }

    public Pet(Integer age) {
        name = "No name yet.";
        weight = 0.0;
        if (age < 0) {
            System.out.println("Error: Negative age.");
            System.exit(0);
        } else {
            this.age = age;
        }
    }

    public Pet(Double weight) {
        name = "No name yet.";
        age = 0;
        if (weight < 0) {
            System.out.println("Error: Negative weight.");
            System.exit(0);
        } else {
            this.weight = weight;
        }
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Double getWeight() {
        return weight;
    }

    public void setWeight(Double weight) {
        this.weight = weight;
    }

    public int compareTo(Object o)
    {
        if(o!=null&&o instanceof Pet)
        {
            Pet pet=(Pet) o;
            return this.age.compareTo(pet.getAge());
        }
        return -1;
    }

    @Override
    public String toString() {
        return "Pet{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", weight=" + weight +
                '}';
    }
}